package com.dqhl.community.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dqhl.community.R;
import com.dqhl.community.model.OrderRecord;
import com.dqhl.community.util.Config;
import com.dqhl.community.util.ViewHolder;

import org.xutils.x;

import java.util.List;

/**
 * Created by mac on 16/11/18.
 * 订单adapter
 */
public class OrderListAdapter extends BaseAdapter {

    private Context context;
    private List<OrderRecord> orderRecordList;
    private LayoutInflater inflater;

    public OrderListAdapter(Context context, List<OrderRecord> orderRecordList) {
        this.context = context;
        this.orderRecordList = orderRecordList;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return orderRecordList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.lv_fragment_unorder_item, parent, false);
        }

        TextView tv_order_id = ViewHolder.get(convertView, R.id.tv_order_id);
        TextView tv_status = ViewHolder.get(convertView, R.id.tv_status);
        ImageView iv_pic = ViewHolder.get(convertView, R.id.iv_pic);
        TextView tv_name = ViewHolder.get(convertView, R.id.tv_name);
        TextView tv_price = ViewHolder.get(convertView, R.id.tv_price);
        TextView tv_total_number = ViewHolder.get(convertView, R.id.tv_total_number);
        TextView tv_total_money = ViewHolder.get(convertView, R.id.tv_total_money);
        TextView tv_pingjia = ViewHolder.get(convertView, R.id.tv_evaluate);

        OrderRecord orderRecord = orderRecordList.get(position);
        String orderId = orderRecord.getName();
        String status = orderRecord.getStatus();
        OrderRecord.Good goods = orderRecord.getGoods().get(0);
        String imgPath = Config.Api.img_url + goods.getGoods_pic();
        String name = goods.getName();
        String price = goods.getPrice_one();
        String total_number = orderRecord.getNumber() + "";
        String total_money = orderRecord.getTotal();

        //显示订单状态
        switch (status) {
            case "1":
                tv_status.setText("订单已生成");
                break;
            case "2":
                tv_status.setText("已取消");
                break;
            case "3":
                tv_status.setText("付款成功");
                break;
            case "4":
                tv_status.setText("货到付款");
                break;
            case "5":
                tv_status.setText("已发货");
                break;
            case "6":
                tv_status.setText("配送中");
                break;
            case "7":
                tv_status.setText("货到付款已支付");
                break;
            case "8":
                tv_status.setText("买家签收");
                break;
            case "9":
                tv_status.setText("他人代收");
                break;
            case "10":
                tv_status.setText("签收异常");
                break;
            case "11":
                tv_status.setText("退货");
                break;
            case "12":
                tv_status.setText("退款");
                break;
            case "13":
                tv_status.setText("订单完成");
                break;
        }
        tv_order_id.setText(orderId);
        x.image().bind(iv_pic, imgPath);
        tv_name.setText(name);
        tv_price.setText(price);
        tv_total_number.setText(total_number);
        tv_total_money.setText(total_money);

        return convertView;
    }
}
